#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <linux/input.h>
#include "main.h"

static int g_stickerVal[4];
int g_adc128d181;
int RemoteStickerInit(void);

int remote_main(void)
{
	RemoteStickerInit();
	uint16_t adcVal[8] = {0};
	while(1) {
		struct timeval logTime[2];
		gettimeofday(&logTime[0], NULL);
		memset(adcVal, 0, sizeof(adcVal));
		int ret = read(g_adc128d181, adcVal, sizeof(adcVal));
		usleep(1000 * 10); // 100Hz input
		gettimeofday(&logTime[1], NULL);
		LOGScroll(5, "input[%fms] ret[%d] [0x%04x | %4d] [0x%04x | %4d]", TimeDiffMillSec(logTime[1], logTime[0]), ret, adcVal[0], adcVal[0], adcVal[1], adcVal[1]);
	}
	close(g_adc128d181);
	return 0;
}

int RemoteStickerInit(void)
{
	g_adc128d181 = open("/dev/KoAdc128d818", O_RDONLY | O_NONBLOCK);
	LOG("RemoteStickerInit open with handle[%d]\n", g_adc128d181);
	return 0;
}

